<template lang="html">
  <section class="components-index_banner" v-if="banners && banners.length > 0">
    <div class="banner-pagination-wrapper">
      <ul class="banner-pagination">
        <li class="pagination-item" :class="{ active: index === activeIndex }" v-for="(n, index) in banners">
          <i class="ic-round"></i>
        </li>
      </ul>
    </div>
    <swiper :options="swiperOption" ref="mySwiper">
      <swiper-slide v-for="banner in banners" :key="banner.bannerImg">
        <div class="banner-img" @click="routeTo(banner.eventUrl)">
          <progressive-img fullMode :src="banner.bannerImg" alt=""/>
        </div>
      </swiper-slide>
      <!-- Optional controls -->
      <!-- <div class="swiper-pagination"  slot="pagination"></div>
      <div class="swiper-button-prev" slot="button-prev"></div>
      <div class="swiper-button-next" slot="button-next"></div>
      <div class="swiper-scrollbar"   slot="scrollbar"></div> -->
    </swiper>
  </section>
</template>

<script>
import Vue from 'vue'
import { swiper, swiperSlide } from 'vue-awesome-swiper'

let evtBus = new Vue()

export default {
  name: 'IndexBanner',
  props: {
    banners: {
      type: Array,
      required: true
    }
  },
  components: {
    swiper,
    swiperSlide
  },
  data(){
    return {
      activeIndex: 0,
      swiperOption: {
        // NotNextTick is a component's own property, and if notNextTick is set to true, the component will not instantiate the swiper through NextTick, which means you can get the swiper object the first time (if you need to use the get swiper object to do what Things, then this property must be true)
        // notNextTick是一个组件自有属性，如果notNextTick设置为true，组件则不会通过NextTick来实例化swiper，也就意味着你可以在第一时间获取到swiper对象，假如你需要刚加载遍使用获取swiper对象来做什么事，那么这个属性一定要是true
        notNextTick: true,
        // autoplay: 1500,
        direction : 'horizontal',
        // autoWidth: true,
        // loop: true,
        // debugger: true,
        onSlideChangeStart(swiper){
          evtBus.$emit('indexChange', swiper.activeIndex)
        },
      }
    }
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.swiper
    }
  },
  methods: {
    routeTo(url){
      window.location.href = url
    }
  },
  created(){
    let self = this
    evtBus.$on('indexChange', function(index){
      self.activeIndex = index
    })
  },
}
</script>

<style lang="scss" scoped>
@import "../css/config";
.components-index_banner{
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  .banner-img{
    width: 100%;
    height: 215px;
    line-height: 215px;
    background-color: #333;
    text-align: center;
    color: #fff;
    img{
      display: inline-block;
      height: 100%;
    }
  }
  .banner-pagination-wrapper{
    position: absolute;
    z-index: 100;
    bottom: 0px;
    left: 0;
    width: 100%;
    height: 46px;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    .banner-pagination{
      height: 100%;
      display: flex;
      flex-flow: row nowrap;
      justify-content: center;
      align-items: center;
      .pagination-item{
        position: relative;
        width: 35px;
        height: 35px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        i{
          display: block;
          margin-top: 3px;
          font-size: 20px;
          color: #cfcfd0;
        }
        &.active{
          i{
            display: none;
          }
          background: url('../assets/image/icon-pagination-on.png') no-repeat center center;
          background-size: 80%;
        }
      }
    }

    // .banner-pagination{
    //   height: 100%;
    //   display: flex;
    //   flex-flow: row nowrap;
    //   justify-content: center;
    //   align-items: center;
    //   .pagination-item{
    //     position: relative;
    //     width: 35px;
    //     height: 35px;
    //     display: flex;
    //     flex-direction: column;
    //     justify-content: center;
    //     align-items: center;
    //     .icon-circle{
    //       position: absolute;
    //       z-index: 1;
    //       top: 0;
    //       left: 0;
    //       display: block;
    //       width: 100%;
    //       height: 100%;
    //       display: flex;
    //       flex-direction: column;
    //       justify-content: center;
    //       align-items: center;
    //       &::before{
    //         display: none;
    //         // display: block;
    //         content: '';
    //         width: 30px;
    //         height: 30px;
    //         border-radius: 100%;
    //         border: 1px solid $common-red;
    //         background-color: transparent;
    //       }
    //     }
    //     i{
    //       font-size: 20px;
    //       color: #cfcfd0;
    //     }
    //     &.active{
    //       .icon-circle::before{
    //         display: block;
    //       }
    //       i{
    //         color: $common-red;
    //       }
    //     }
    //   }
    // }
  }
}
</style>
